package org.styx.seata.tcc.storage.service;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.styx.seata.tcc.storage.mapper.StorageMapper;
import org.styx.seata.tcc.storage.tcc.StorageTccAction;


@Service
@Slf4j
@RequiredArgsConstructor
public class StorageService  {

    private final StorageMapper storageMapper;

    private final StorageTccAction storageTccAction;

    /**
     * 扣减库存
     */
    public void decrease(Long productId, Integer count) {
        log.info("------->storage-service中扣减库存开始!!!!!");
        //storageMapper.decrease(productId,count);
        storageTccAction.prepareDecreaseStorage(null,productId,count);
        log.info("------->storage-service中扣减库存结束#####");
        //todo 分支服务模拟异常
       /* if(Math.random()<1.0){
            throw new RuntimeException("模拟异常");
        }*/
    }
}
